/*
 * Copyright 2008 Federal Emergency Management Agency
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 *    
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *  
 */
package gov.fema.hazus.bdc.client.hazards.earthquake.secondarycharacteristics;

import gov.fema.hazus.bdc.shared.entity.EarthquakeSecondaryCharacteristics;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;

public class EarthquakeSecondaryCharacteristicsListBoxChangeListener implements EarthquakeSecondaryCharacteristicsListBoxChangeListenerInterface {

	private EarthquakeSecondaryCharacteristics earthquakeSecondaryCharacteristics;
	
	public EarthquakeSecondaryCharacteristicsListBoxChangeListener(EarthquakeSecondaryCharacteristics earthquakeSecondaryCharacteristics)
	{
		this.earthquakeSecondaryCharacteristics = earthquakeSecondaryCharacteristics;
	}
	
	public void onChange(Widget sender) {
		
		ListBox listBox = (ListBox) sender;
		String value = listBox.getValue(listBox.getSelectedIndex());
		String listName = listBox.getName();

		if( listName.equals( EarthquakeSecondaryCharacteristics.HORIZONTAL ) )
		{
			GWT.log( EarthquakeSecondaryCharacteristics.HORIZONTAL + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setHorizontalShape(value);
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.VERTICAL ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.VERTICAL + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setVerticalShape(value);
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.TORSION ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.TORSION + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setTorsion(value);		
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.SOFTSTORY ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.SOFTSTORY + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setSoftStory(value);	
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.SHORTCOLUMNS ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.SHORTCOLUMNS + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setShortColumns(value);	
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.POUNDING ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.POUNDING + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setPounding(value);	
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.URMRETROFIT ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.URMRETROFIT + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setURMRetrofit(value);
		} else if ( listName.equals( EarthquakeSecondaryCharacteristics.ORNAMENTATION ) ) {
			GWT.log( EarthquakeSecondaryCharacteristics.ORNAMENTATION + ": " + value, null);
			this.earthquakeSecondaryCharacteristics.setOrnamentation(value);				
		} else {
			// do nothing
		}

	}

	public void updateEarthquakeSecondaryCharacteristics(EarthquakeSecondaryCharacteristics earthquakeSecondaryCharacteristics) {
		this.earthquakeSecondaryCharacteristics = earthquakeSecondaryCharacteristics;
	}

}
